package org.opens.mybatisplus.controller;

import org.opens.mybatisplus.entity.BasParamEntity;
import org.opens.mybatisplus.service.RedisService;
import org.opens.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能:
 *
 * @author zym
 * @Date 2022/1/10 17:34
 */
@RestController
@RequestMapping(value = "/api/redis-cache")
public class RedisController {

    @Autowired
    private RedisService redisService;

    @GetMapping(value = "/{hosNum}/{key}")
    public R getCache(
            @PathVariable(value = "key") String key, @PathVariable(value = "hosNum") String hosNum
    ) {
        BasParamEntity basParamEntity = redisService.findByName(hosNum, key);
        R r = R.success("查询成功");
        r.put("data", basParamEntity);
        return r;
    }

    @GetMapping(value = "/refuse/{hosNum}/{key}")
    public R getCache2(
            @PathVariable(value = "key") String key, @PathVariable(value = "hosNum") String hosNum
    ) {
        BasParamEntity basParamEntity = redisService.findByName2(hosNum, key);
        R r = R.success("查询成功");
        r.put("data", basParamEntity);
        return r;
    }

}
